package hut.lvming.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import hut.lvming.dao.RecordMapper;
import hut.lvming.domain.Record;
import hut.lvming.domain.User;
import hut.lvming.entity.PageResult;
import hut.lvming.service.RecoedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RecordServiceImpl implements RecoedService {
    @Autowired(required = false)
    private RecordMapper recordMapper;

    @Override
    public Integer addRecord(Record record) {
        System.out.println("**********************RecordService.addRecord()************************************");
        System.out.println(record);
        System.out.println("**********************RecordService.addRecord()************************************");
        return recordMapper.addRecord(record);
    }

    @Override
    public PageResult searchRecords(Record record, User user, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        if(!"ADMIN".equals(user.getRole())){
            record.setBorrower(user.getName());
        }
        Page<Record> page=recordMapper.searchRecords(record);
        return new PageResult(page.getTotal(),page.getResult());
    }
}
